package com.xianggu.spring.aop.joinPoint;

import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author chengjy
 * @date 2025/3/11
 */
public class CglibJoinPoint implements ProceedingJoinPoint {

    private Method method;
    private MethodProxy methodProxy;

    private Object[] args;

    private Object target;


    /**
     * 执行目标方法
     * @return
     */
    @Override
    public Object proceed(){
        try {
            return methodProxy.invokeSuper(target , args);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("目标方法执行失败！proceed" + e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException("目标方法执行失败！proceed" + e);
        } catch (Throwable e) {
            throw new RuntimeException("目标方法执行失败！proceed" + e);
        }
    }

    public CglibJoinPoint(Method method, MethodProxy methodProxy, Object[] args, Object target) {
        this.method = method;
        this.args = args;
        this.target = target;
        this.methodProxy = methodProxy;
    }



    public Method getMethod() {
        return method;
    }

    public Object[] getArgs() {
        return args;
    }
}
